<?php
namespace Admin\Controller;
use Think\Controller;
class NavController extends BaseController {
    public function nav_list(){
    	
		$nav=M('nav')->order('nav_ord asc')->select();
		$a=1;
		$this->assign('nav',$nav);
		$this->assign('a',$a);
        $this->display();
    }
    public function nav_add(){
    	if(I('post.')){
    		$data=array(
    			'nav_name'=>I('post.nav_name'),
                'nav_url'=>I('post.nav_url'),
    			'nav_ord'=>I('post.nav_ord'),
    		);
    		$res=M('nav')->add($data);
    		if($res){
    			$this->success('添加成功',U('Admin/nav/nav_list'));
    			exit();
    		}else{
    			$this->error('数据有误，请重新提交');
    		}
    	}
    	$this->display();
    }
    public function nav_edit(){
    	$aid=I('get.aid');
    	$nav=M('nav')->where("nav_id=$aid")->find();
    	$this->assign('nav',$nav);
    	if(I('post.')){
    		$data=array(
    			'nav_name'=>I('post.nav_name'),
                'nav_url'=>I('post.nav_url'),
                'nav_ord'=>I('post.nav_ord'),
    		);
            $nav_id=I('post.nav_id');
    		$res=M('nav')->where("nav_id=$nav_id")->save($data);
    		if($res){
    			$this->success('编辑成功',U('Admin/nav/nav_list'));
    			exit();
    		}else{
    			$this->error('数据有误，请重新提交');
    			exit();
    		}
    	}
    	$this->display();
    }
    public function nav_del(){
    	$a_id=I('get.a_id');
		$res=M('nav')->where("nav_id=$a_id")->delete();
		if($res){
			echo 1;exit();
		}else{
			echo M('nav')->getLastSql();exit();
		}
    }
}